package com.coin.exchanges.view.user

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.coin.exchanges.R
import com.coin.exchanges.net.RetrofitFactory
import com.coin.exchanges.presenter.TestPresenter
import com.coin.exchanges.utils.LCSharedPreferencesHelper
import com.coin.exchanges.utils.SpUtils
import com.coin.exchanges.view.MainActivity
import com.coin.exchanges.view.user.bean.UerInfoBean
import com.coin.exchanges.view.user.bean.UserLoginBean
import com.coin.libbase.view.activity.JToolbarActivity
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_user_info.*
import java.util.HashMap

class UserInfoActivity : JToolbarActivity<TestPresenter>() {
    override fun getLayout(): Int {
        return R.layout.activity_user_info
    }

    override fun initIntent(intent: Intent?) {
    }

    override fun initView() {
        setToolbarBackground(R.color.white)
        title = "个人账户信息"
    }

    override fun initData() {
        val sharedPreferencesHelper = LCSharedPreferencesHelper.instance(this@UserInfoActivity, "register")

        val userId = sharedPreferencesHelper.getValue("UserId")
        val map = HashMap<String, String>()
        map["user_id"] =userId
        RetrofitFactory
                .getOkExApiService()
                .info(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : Observer<UerInfoBean> {
                    override fun onNext(mUserLoginBean: UerInfoBean) {
                        UserName.text=mUserLoginBean.data.get(0).UserName
                        UserPhone.text=mUserLoginBean.data.get(0).UserPhone
                        UserMoney.text=mUserLoginBean.data.get(0).UserMoney.toString()

                    }


                    override fun onSubscribe(d: Disposable) {

                    }

                    override fun onError(e: Throwable) {

                    }

                    override fun onComplete() {

                    }
                })
    }


}
